<?php

namespace app\api\Logic\Online;

use app\api\model\OnlineVideoModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;

class OnlineVideoLogic
{
    /**
     * 获取课程详情
     * @param $shopId
     * @param $videoId
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getInfo($shopId,$videoId){
        $info = OnlineVideoModel::where('shop_id',$shopId)
            ->where('id',$videoId)
            ->with([
                'videoTypeInfo' => function ($query) {
                    $query->withField('id,name');
                },
                'sublevelList' => function ($query){
                    $query->withField('id,video_id,title,image,video_length,createtime');
                }
            ])->field('id,type_id,title,image,content,price,study_number,type,user_ids,checked_phone')
            ->find();

        return objToArray($info) ?? [];
    }
}
